<template>
  <div class="level">
    <h1>医院</h1>
    <div class="content">
      <div class="left">等级:</div>
      <ul class="hospital">
        <li :class="activeFlag == '' ? 'active' : ''" @click="changeLevel('')">
          全部
        </li>
        <li
          v-for="item in hospitalLevelArr"
          :key="item.id"
          :class="activeFlag == item.value ? 'active' : ''"
          @click="changeLevel(item.value)"
        >
          {{ item.name }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reqHospitalLevelAndRegion } from "@/api/home";
import {
  HospitalLevelAndRegionResponseData,
  HospitalLevelAndRegionArr,
} from "@/api/home/type.ts";
import { onMounted, ref, defineEmits } from "vue";

const $emit = defineEmits(["getLevel"]);

const hospitalLevelArr = ref<HospitalLevelAndRegionArr>([]);

// 控制医院等级高亮
let activeFlag = ref("");
const changeLevel = (levelValue: string) => {
  $emit("getLevel", levelValue);
  activeFlag.value = levelValue;
};

const getLevel = async () => {
  let data: HospitalLevelAndRegionResponseData =
    await reqHospitalLevelAndRegion("Hostype");
  hospitalLevelArr.value = data.data;
};

onMounted(() => {
  getLevel();
});
</script>

<style scoped lang="scss">
.level {
  color: #7f7f7f;
  h1 {
    font-weight: 900;
    font-size: 16px;
  }
  .content {
    margin-top: 20px;
    display: flex;

    .left {
      margin-right: 10px;
      width: 40px;
    }

    .hospital {
      display: flex;
      li {
        margin-right: 10px;
        &.active {
          color: #165dff;
        }
        &:hover {
          color: #165dff;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
